<?php
	class IcmsStDAO{
		protected $db;

		public function __construct ($db){
			$this->db = $db;
		}

		public function setDb($db){
			$this->db = $db;
		}

		public function getDb(){
			return $this->db;
		}

		public function setIcmsSt($i){
			$sql = "update icms_st set perc_revenda = '{$i->getPercRevenda()}', perc_consumidor = '{$i->getPercCf()}'
					where icms_st = {$i->getId()}";				
			$res = $this->getDb()->update($sql);
			return $res;
		}

		public function getLista($where=array()){
			$where = ($where ? "where ".implode(" and ",$where) : "");
			$lista = array();

			$sql = "select ICMS_ST, UF, PERC_REVENDA, PERC_CONSUMIDOR
					from icms_st
					{$where}
					order by uf";
			$res = $this->getDb()->query($sql);

			if($res){
				foreach($res as $r){
					$lista[] = new IcmsSt($r['ICMS_ST'],$r['UF'],$r['PERC_REVENDA'],$r['PERC_CONSUMIDOR']);
				}
			}

			return $lista;
		}
	}
?>